@include('admin.public.head')

<div class="ibox-title">
    <h5>課程添加</h5></br></br>
    <h5>@if(isset($home)) 安排老師：{{$home['teacher']}} 安排時間：{{$home['base_time']['week']}} {{$home['base_time']['time_start_hour']}}:{{$home['base_time']['time_start_minute']}} ~  {{$home['base_time']['time_end_hour']}}:{{$home['base_time']['time_end_minute']}}@endif</h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-3 control-label">上课周期：</label>
            <div class="col-sm-3">
                <select class="form-control" name="week" >
                    <option value="" >请选择周期</option>
                    @foreach($week_lists as $k=>$v)
                       <option value="{{$k}}" >{{$v}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">時間段：</label>
            <div class="col-sm-3 text-center">
                <select class="form-control" name="base_time" onchange="change($(this))">

                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上課時長：</label>
            <div class="col-sm-3">
                <input type="text" name="class_duration" class="form-control" placeholder="上課時長" value="" disabled>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">門店分類：</label>
            <div class="col-sm-3">
                <select class="form-control" name="store_id" id="store_id">
                    <option value="" >請選擇門店</option>
                    @foreach($select_store as $k=>$v)
                        <option value="{{$k}}" @if($select_id == $k) selected="selected" @endif>{{$v}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課程名稱：</label>
            <div class="col-sm-3 text-center">
                <select class="form-control" name="class_base" >

                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">老師：</label>
            <div class="col-sm-3 text-center ">
                <select class="form-control" name="teacher" >

                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課室：</label>
            <div class="col-sm-3 text-center">
                <select class="form-control" name="classroom" >

                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">允許多少分鐘前取消預約：</label>
            <div class="col-sm-3">
                <input type="number" name="advance_cancel_time" class="form-control" placeholder="允許多少分鐘前取消預約" value="">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上課人數：</label>
            <div class="col-sm-3">
                <input type="number" name="class_number_people" class="form-control" placeholder="上課人數" value="">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">是否camp：</label>
            <div class="col-sm-9">
                <label value="1">
                    <input type="radio" name="is_camp"  value="1">是
                </label>
                <label value="0">
                    <input type="radio" name="is_camp"  value="2">否
                </label>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <a href="javascript:void(0)" class="btn btn-primary do" type="submit">操作</a>
                <a href="/class_base_info" class="btn btn-primary" >返回安排列表</a>
            </div>
        </div>
    </form>
</div>

<script>
    $('.do').click(function(){
        var form = new FormData();

        var week = $('select[name="week"] option:selected').val();
        var base_time_id = $('select[name="base_time"] option:selected').val();
        var base_time = $('select[name="base_time"] option:selected').text();
        var class_duration = $('input[name="class_duration"]').val();
        var advance_cancel_time = $('input[name="advance_cancel_time"]').val();
        var class_number_people = $('input[name="class_number_people"]').val();
        var is_camp = $('input[name="is_camp"]:checked').val();
        if(typeof(is_camp) == 'undefined')is_camp = '';


        var store_id = $('select[name="store_id"] option:selected').val();
        var class_base_id = $('select[name="class_base"] option:selected').val();
        var teacher = $('select[name="teacher"] option:selected').val();
        var classroom_id = $('select[name="classroom"] option:selected').val();

        form.append("class_week", week);
        form.append("class_base_id", class_base_id);
        form.append("advance_cancel_time", advance_cancel_time);
        form.append("class_time", base_time);
        form.append("class_time_id", base_time_id);
        form.append("class_number_people", class_number_people);
        form.append("teacher_id", teacher);
        form.append("store_id", store_id);
        form.append("class_classroom_id", classroom_id);
        form.append("is_camp", is_camp);
        form.append("class_duration", class_duration);

        $.ajax({
            type: 'POST',
            url: '/class_base_info_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        //window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });
</script>

<script>
    var class_base_id = "{{$class_base_id??0}}";
    var teacher_id = "{{$teacher_id??0}}";
    var classroom_id = "{{$classroom_id??0}}";
    var base_time_id = "{{$base_time_id??0}}";

    function change(obj){
        var duration = obj.find("option:selected").attr('duration');

        if(duration != 'null')$("input[name='class_duration']").val(duration);
    }
</script>

<script type="text/javascript" src="{{ URL::asset('./admin/js/reservation/classroom_teacher_classbase.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('./admin/js/reservation/class_base_time.js') }}"></script>

